package com.hntx.joymusic.yun;

import android.text.TextUtils;
import android.util.Log;

import com.google.gson.JsonObject;
import com.hntx.joymusic.Constants;
import com.hntx.joymusic.sytRetrofity.SytRetrofit;
import com.hntx.joymusic.util.GsonUtils;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;


public class YunUtils {
    private static String TAG = "YunUtils";
    //appSignature生成算法
    //hmac_sha1(“appKey=相应的值&timestamp=相应的值”, appSecret)

    public static String sign(String token, String method, String url, String date) {
        String sign = "AccessToken=" + token + "&Operate=" + method + "&RequestURI="
                + url + "&Date=" + date;
        sign = HmacUtils.hmacsha1(sign, Constants.appYunSecret);
        return sign;
    }

    public static String getPath(String requestUrl) {
        String urlStr = null;
        try {
            URL url = new URL(requestUrl);
            urlStr = url.getPath();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return urlStr;
    }

    public static String getDateStr() {
        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss");
        String datestr = date.format(new Date());
        return datestr;
    }


    public static void yunInit(YunInitListener listener) {
        Observable.create(emitter -> YunUtils
                .createAccount(Constants.openAccount, Constants.openArea,
                        msg -> {
                            CreateAccountBean bean = GsonUtils.getGson()
                                    .fromJson(msg, CreateAccountBean.class);
                            emitter.onNext(bean.getOpenAccount());

                        }))
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .flatMap((Function<Object, ObservableSource<?>>) obj -> {
                    Long timestamp = System.currentTimeMillis();
                    String appSignature = HmacUtils.hmacsha1("appKey="
                                    + Constants.yunAppkey + "&timestamp=" + timestamp,
                            Constants.appYunSecret);
                    Log.d(TAG, "SIGNATURE:" + appSignature);
                    return SytRetrofit.getInstance().getYunToken(Constants.yunAppkey, appSignature,
                            Constants.grant_type, String.valueOf(obj), timestamp);

                }).flatMap(new Function<Object, ObservableSource<?>>() {

            @Override
            public ObservableSource<?> apply(Object msg) throws Exception {
                String request = "https://api-b.cloud.189.cn/api/listCorp.action";
                YunTokenBean tokenbean = GsonUtils.getGson().fromJson(msg.toString(), YunTokenBean.class);
                String datestr = YunUtils.getDateStr();
                String requestUrl = YunUtils.getPath(request);
                Constants.yunToken = tokenbean.getAccessToken();
                String appSignature = YunUtils.sign(tokenbean.getAccessToken(), "POST", requestUrl, datestr);
                return SytRetrofit.getInstance().queryYunList(tokenbean.getAccessToken(),
                        appSignature, datestr, Constants.yunAppkey);
            }
        }).flatMap(new Function<Object, ObservableSource<?>>() {
            @Override
            public ObservableSource<?> apply(Object o) throws Exception {
                ListCorpBean listCorpBean = GsonUtils.getGson().fromJson(o.toString(), ListCorpBean.class);
                String paths = "https://api-b.cloud.189.cn/api/createCompanyFolder.action";
                paths = YunUtils.getPath(paths);
                String dates = YunUtils.getDateStr();
                Constants.corpId = listCorpBean.getData().get(0).getCorpId();
                String appsign = YunUtils.sign(Constants.yunToken, "POST", paths, dates);
                return SytRetrofit.getInstance()
                        .createCorpFiles(Constants.yunToken, appsign, dates,
                                Constants.yunAppkey, Constants.corpId,
                                listCorpBean.getData().get(0).getCorpFolderId(),
                                Constants.fileName);
            }
        }).subscribe(new Observer<Object>() {

            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object obj) {
                if (TextUtils.isEmpty(obj.toString())) return;
                CreateFileBean listCorpBean = GsonUtils.getGson().fromJson(obj.toString(), CreateFileBean.class);
                if (listener != null) {
                    listener.yunInitResult(listCorpBean);
                }

            }

            @Override
            public void onError(Throwable e) {
                Log.d(TAG, "DDDDD" + e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }

    public static void createAccount(String openAccount, String openArea, YunOpenListener listener) {
        //销售品ID
        //CORP_COM_PRODUCT  普通版
        //CORP_GOLD_PRODUCT 黄金版
        //CORP_PLATI_PRODUCT 白金版
        //CORP_PROF_PRODUCT 钻石版
        String timestamp = String.valueOf(System.currentTimeMillis());
        String content = "openAccount=" + openAccount + "&openArea=" + openArea + "&saleProdId=CORP_COM_PRODUCT";
        byte[] enByte = null;
        try {
            enByte = XXteaUtils.encrypt(content.getBytes("UTF-8")
                    , Constants.appYunSecret.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String format = "json";
        String version = "v1.0";
        String paras = HmacUtils.tohex(enByte);
        Log.d(TAG, "PARASS:" + paras);
        //sign=HMAC-SHA1(appKey+timeStamp+format+version+paras,appSecret)
        String signs = Constants.yunAppkey + timestamp + format + version + paras;
        String sign = HmacUtils.hmacsha1(signs, Constants.appYunSecret);

        Observable<JsonObject> ob = SytRetrofit.getInstance()
                .createAccount(Constants.yunAppkey, timestamp, format, version, paras,
                        sign);
        if (ob != null) {
            ob.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<JsonObject>() {
                        @Override
                        public void onSubscribe(Disposable d) {

                        }

                        @Override
                        public void onNext(JsonObject jsonObject) {
                            Log.d(TAG, "云初始化结果：" + jsonObject);
                            if (listener != null) {
                                listener.openResult(jsonObject);
                            }
                        }

                        @Override
                        public void onError(Throwable e) {
                            Log.d(TAG, "云初始化cuowu结果：" + e.getMessage());
                        }

                        @Override
                        public void onComplete() {

                        }
                    });
        }
    }

    public static void getToken(String deviceAccount, YunListener listener) throws Exception {
        Long timestamp = System.currentTimeMillis();
        String appSignature = HmacUtils.hmacsha1("appKey=" + Constants.yunAppkey + "&timestamp=" + timestamp,
                Constants.appYunSecret);
        Log.d(TAG, "SIGNATURE:" + appSignature);
        Observable<JsonObject> ob = SytRetrofit.getInstance().getYunToken(Constants.yunAppkey, appSignature,
                Constants.grant_type, deviceAccount, timestamp);
        if (ob != null) {
            ob.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<JsonObject>() {
                        @Override
                        public void onSubscribe(Disposable d) {
                        }

                        @Override
                        public void onNext(JsonObject tokenJson) {
                            Log.d(TAG, "云初始化结果：" + tokenJson);
//                            if (listener != null) {
//                                listener.getToken(tokenBean.getAccessToken());
//                            }
                        }

                        @Override
                        public void onError(Throwable e) {
                            if (listener != null)
                                listener.onError(e.getMessage());
                        }

                        @Override
                        public void onComplete() {
                        }
                    });
        }
    }


    //3.2合作方与云盘绑定关系接口定义
    public static void bindRelation() {
        String appKey, timeStamp;
    }

    /**
     * 查询企业云列表（该合作应用的企业云）
     * https://api-b.cloud.189.cn/api/listCorp.action
     * header :AccessToken  Signature  Date
     * 返回值
     * {
     * "data": [
     * {
     * "corpId": 113482191,
     * "corpName": "阿波罗",
     * "createTime": "2016-7-19 16:29:38",
     * "modifyTime": "2016-7-19 16:29:38",
     * "wqId": "wxdf3961ec7a7c8657",
     * "managerName": "Dave",
     * "isCreator": 0,
     * "userRole":2,
     * "corpFolderId": "123",
     * "shareFolderId": "11234",
     * "corpUserId": "9208",
     * "maxFileSize": 4294967296
     * },
     * {
     * "corpId": "113482192",
     * "corpName": "阿波罗2",
     * "createTime": "2016-7-19 16:29:38",
     * "modifyTime": "2016-7-19 16:29:38",
     * "wqId": "wxdf3961ec7a7c8653",
     * "managerName": "Dave",
     * "isCreator": 1,
     * "userRole": 1,
     * "corpFolderId": "456",
     * "shareFolderId": "11234345",
     * "corpUserId": "9080",
     * "maxFileSize": 4294967296
     * }
     * ]
     * }
     */

    public static void queryYunList(String accessToken, String signature, String date, ListBeanListener listBeanListener) {
        Observable<JsonObject> ob = SytRetrofit.getInstance()
                .queryYunList(accessToken, signature, date, Constants.yunAppkey);
        ob.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<JsonObject>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(JsonObject jsonObject) {
                        Log.d(TAG, "SHOUHUO:" + jsonObject);
                        ListCorpBean listCorpBean = GsonUtils.getGson().fromJson(jsonObject, ListCorpBean.class);
                        if (listBeanListener != null) {
                            listBeanListener.YunListResult(listCorpBean);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, "queryYunList结果：" + e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * 获取企业信息
     * https://api-b.cloud.189.cn/api/getCorpInfo.action
     * 请求参数 corpId
     * 返回参数
     * {
     * "corpId":113482191,
     * "corpName":"阿波罗",
     * "createTime":"2016-7-19 16:29:38",
     * "modifyTime":"2016-7-19 16:29:38",
     * "wqId":"wxdf3961ec7a7c8657",
     * "isCreator": 1,
     * "managerName": "Dave",
     * "isPro": true,
     * "isExpire":false,
     * "maxFileSize": 4294967296,
     * “saleChannel”:1,
     * “status”:1,
     * “corpUserId”:”42522652”
     * }
     */

    public static void getCorpInfo(String corpId, String accessToken, String signature, String date) {
        Observable<String> ob = SytRetrofit.getInstance()
                .getCorpInfo(corpId, accessToken, signature, date);
    }


    /**
     * 获取企业成员列表
     * https://api-b.cloud.189.cn/api/listCorpUser.action
     * 请求参数 String corpId
     * Long userRole pageNum  pageSize   都是可选参数
     * 返回结果
     * {
     * "data": [
     * {
     * "userId": 1135,
     * "corpId": 123,
     * "userName": "无极",
     * "userRole": 1,
     * "mobile": "18022334466",
     * "email": "666333111@qq.com",
     * "position": "经理",
     * "departmentList": [
     * {
     * "departmentId": "113482351",
     * "name": "财务部",
     * "parentId": "0"
     * },
     * {
     * "departmentId": "113482351",
     * "name": "财务部",
     * "parentId": "0"
     * }
     * ]
     * },
     * {
     * "userId": 1123,
     * "corpId": 123,
     * "userName": "小小",
     * "userRole": 3,
     * "mobile": "18022334466",
     * "email": "666333111@qq.com",
     * "position": "成员",
     * "departmentList": []
     * }
     * ],
     * "pageNum": 1,
     * "pageSize": 2,
     * "recordCount": 10
     * }
     */

    public static void getCorpMemberList(String corpId, String accessToken, String signature, String date) {
        Observable<String> ob = SytRetrofit.getInstance()
                .getCorpMemberList(corpId, accessToken, signature, date);
    }

    /**
     * 获取指定的文件夹下的子文件和文件夹列表。
     * listCompanyFiles.action
     */
    public static void getSpecifiedFiles(Map<String, Object> map, String accessToken, String signature, String date) {
        Observable<String> ob = SytRetrofit.getInstance()
                .getSpecifiedFiles(map, accessToken, signature, date);
    }

    /**
     * 创建公司文件夹
     * https://api-b.cloud.189.cn/api/createCompanyFolder.action
     * corpId  parentId  fileName
     * <p>
     * appKey	true	String	应用编码
     * corpId	true	String	公司ID
     * parentId	true	String	父目录ID
     * fileName	true	String	文件夹名称
     */

    public static void createCorpFiles(String accessToken, String signature,
                                       String date, String appKey, String corpId,
                                       String parentId, String fileName, CreateFileListener listener) {
        Observable<JsonObject> ob = SytRetrofit.getInstance()
                .createCorpFiles(accessToken, signature, date, appKey, corpId, parentId, fileName);
        if (ob != null) {
            ob.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<JsonObject>() {
                        @Override
                        public void accept(JsonObject s) throws Exception {
                            CreateFileBean bean = GsonUtils.getGson().fromJson(s, CreateFileBean.class);
                            if (listener != null)
                                listener.createResult(bean);
                        }
                    });
        }
    }

    /**
     * 批量创建文件夹
     * https://api-b.cloud.189.cn/api/createCompanyFolder.action
     * 请求参数
     * {
     * "corpId": "114341231",
     * "folderList": {
     * "paths": [
     * "100个小文件",
     * "100个小文件/BT"
     * ]
     * }
     * }
     * <p>
     * 返回参数
     * {
     * "data": {
     * "100个小文件": {
     * "result": "213052166901",
     * "success": true
     * },
     * "100个小文件/BT": {
     * "result": "213052166902",
     * "success": true
     * }
     * }
     * }
     */

    public static void piCreateFiles(String accessToken, String signature, String date, PiFiles piFiles) {
        Observable<String> ob = SytRetrofit.getInstance()
                .piCreateFiles(accessToken, signature, date, piFiles);
    }

    /**
     * 查询单个公司文件信息
     * https://api-b.cloud.189.cn/api/getCompanyFileInfo.action
     */

    public static void cxSingleCorpInfo(String accessToken, String signature, String date, String corpId, String fileId) {
        Observable<String> ob = SytRetrofit.getInstance()
                .cxSingleCorpInfo(accessToken, signature, date, corpId, fileId);
    }

    /**
     * 查询单个公司文件信息
     * https://api-b.cloud.189.cn/api/getCompanyFileDownload.action
     */

    public static void cxSingleCorpFileInfo(String accessToken, String signature, String date, String corpId, String fileId) {
        Observable<String> ob = SytRetrofit.getInstance()
                .cxSingleCorpFileInfo(accessToken, signature, date, corpId, fileId);
    }

    /**
     * 删除文件/文件夹
     * https://api-b.cloud.189.cn/api/removeCompanyFile.action
     * 请求参数：fileIdList	true	String	文件ID列表，用”,”分割；
     * 返回参数：
     * {
     * “success”:true
     * }
     */
    public static void deleteFile(String accessToken, String signature, String date, String corpId, String fileIdList) {
        Observable<String> ob = SytRetrofit.getInstance()
                .deleteFile(accessToken, signature, date, corpId, fileIdList);
    }

    /**
     * 重命名文件/文件夹
     * https://api-b.cloud.189.cn/api/renameCompanyFile.action
     * 返回参数 同上一个
     */
    public static void renameFile(String accessToken, String signature, String date, String corpId, String fileId, String fileName) {
        Observable<String> ob = SytRetrofit.getInstance()
                .renameFile(accessToken, signature, date, corpId, fileId, fileName);
    }

    /**
     * 4.5.8复制公司文件到公司文件
     * https://api-b.cloud.189.cn/api/copyCompanyFile.action
     */
    public static void copyFile(String accessToken, String signature, String date, CopyFileToFile fileToFile) {
        Observable<String> ob = SytRetrofit.getInstance()
                .copyFile(accessToken, signature, date, fileToFile);

    }

    /**
     * 创建共享文件夹
     * https://api-b.cloud.189.cn/api/createCoshare.action
     */
    public static void createCoshare(String accessToken, String signature, String date, String corpId, String coshareName) {

        Observable<String> ob = SytRetrofit.getInstance()
                .createCoshare(accessToken, signature, date, corpId, coshareName);

    }

    /**
     * 获取用户共享文件夹列表的数据
     * https://api-b.cloud.189.cn/api/listJoinCorpCoshare.action
     */

    public static void listJoinCorpCoshare(String accessToken, String signature, String date, JoinCorpCoshare corpCoshare) {
        Observable<String> ob = SytRetrofit.getInstance()
                .listJoinCorpCoshare(accessToken, signature, date, corpCoshare);

    }

    /**
     * 共享文件列表
     * https://api-b.cloud.189.cn/api/listCoshareFile.action
     */
    public static void listCoshareFile(String accessToken, String signature, String date, CoShareFile corpCoshare) {
        Observable<String> ob = SytRetrofit.getInstance()
                .listCoshareFile(accessToken, signature, date, corpCoshare);

    }

    /**
     * 批量创建共享文件夹
     * https://api-b.cloud.189.cn/api/createCoshareFolders.action
     * 响应
     * {
     * "data": {
     * "100个小文件": {
     * "result": "213052166901",
     * "success": true
     * },
     * "100个小文件/BT": {
     * "result": "213052166902",
     * "success": true
     * }
     * }
     * }
     */
    public static void createCoshareFolders(String accessToken, String signature, String date, ShareFolders shareFolders) {
        Observable<String> ob = SytRetrofit.getInstance()
                .createCoshareFolders(accessToken, signature, date, shareFolders);
    }

    /**
     * 查询共享文件夹信息
     * https://api-b.cloud.189.cn/api/getCoshareInfo.action
     */

    public static void getCoshareFileInfo(String accessToken, String signature, String date, String corpId, String coshareId) {
        Observable<String> ob = SytRetrofit.getInstance()
                .getCoshareFileInfo(accessToken, signature, date, corpId, coshareId);
    }

    /**
     * 查询单个共享文件信息
     * https://api-b.cloud.189.cn/api/getCoshareFileInfo.action
     */

    public static void getsingleCoshareFileInfo(String accessToken, String signature, String date, String corpId, String coshareId, String fileId) {
        Observable<String> ob = SytRetrofit.getInstance()
                .getsingleCoshareFileInfo(accessToken, signature, date, corpId, coshareId, fileId);
    }

    /**
     * 修改共享文件夹名称
     * https://api-b.cloud.189.cn/api/renamecoshare.action
     */
    public static void renamecoshare(String accessToken, String signature, String date, String corpId, String coshareId, String coshareName) {
        Observable<String> ob = SytRetrofit.getInstance()
                .renamecoshare(accessToken, signature, date, corpId, coshareId, coshareName);

    }

    /**
     * 共享文件夹中创建文件
     * https://api-b.cloud.189.cn/api/createCoshareFile.action
     */
    public static void createCoshareFile(String accessToken, String signature, String date,
                                         String corpId, String coshareId, String parentId, String fileName) {
        Observable<String> ob = SytRetrofit.getInstance()
                .createCoshareFile(accessToken, signature, date, corpId, coshareId, parentId, fileName);
    }

    /**
     * 共享文件夹内文件重命名
     * https://api-b.cloud.189.cn/api/renameCoshareFile.action
     */
    public static void renameCoshareFile(String accessToken, String signature, String date,
                                         String corpId, String coshareId, String fileId, String newFileName) {
        Observable<String> ob = SytRetrofit.getInstance()
                .renameCoshareFile(accessToken, signature, date, corpId, coshareId, fileId, newFileName);
    }

    /**
     * 删除共享文件
     * https://api-b.cloud.189.cn/api/putShareFile2Recycle.action
     */
    public static void putShareFile2Recycle(String accessToken, String signature, String date,
                                            String corpId, String coshareId, String fileIdList) {
        Observable<String> ob = SytRetrofit.getInstance()
                .putShareFile2Recycle(accessToken, signature, date, corpId, coshareId, fileIdList);
    }

    /**
     * 根据用户进行分流，获取一次性上传地址。
     * 根据2.4.1获取用户上传地址上传文件。
     * /corp/putCorpFile
     * POST
     */
    public static void putCorpFileUrl(String accessToken, String signature, String date,
                                      String appKey, String corpId, UpLoadFileUrlListener listener) {

        Observable<JsonObject> ob = SytRetrofit.getInstance()
                .getCorpPutUploadURL(accessToken, signature, date, appKey, corpId);
        if (ob != null) {
            ob.subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(s -> {
                        UpLoadFileUrlBean bean = GsonUtils.getGson().fromJson(s, UpLoadFileUrlBean.class);
                        if (listener != null)
                            listener.upUrlresult(bean);
                    });
        }
    }


    public static void putCorpFile(String accessToken, String signature,
                                   String date, String corpId, String parentId,
                                   String fileName, String size,
                                   String md5, String baseFileId,
                                   String fileSource, String coshareId) {
        Map<String, String> map = new HashMap();
        map.put("AccessToken", accessToken);
        map.put("Signature", signature);
        map.put("Date", date);
        map.put("CorpId", corpId);
        map.put("ParentId", parentId);
        map.put("FileName", fileName);
        map.put("Size", size);
        map.put("Md5", md5);
        map.put("OperType", "3");
        map.put("BaseFileId", baseFileId);
        map.put("FileSource", fileSource);
        map.put("CoshareId", coshareId);
//        Observable<String> ob = SytRetrofit.getInstance().putCorpFile(map);
    }


    /**
     * 创建一个上传文件用于保存断点续传的文件，用于1M以上文件上传。
     * <p>
     * https://api-b.cloud.189.cn/api/createCorpUploadFile.action
     * POST
     */
    public static void createCorpUploadFile(String accessToken, String signature, String date,
                                            Long corpId, Long parentId, String fileName,
                                            Long size, String md5, Long baseFileId,
                                            Long fileSource, Long coshareId, Long islog) {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("AccessToken", accessToken);
        headerMap.put("Signature", signature);
        headerMap.put("Date", date);
        CorpUploadFile uploadFile = new CorpUploadFile();
        uploadFile.setCorpId(corpId);
        uploadFile.setParentId(parentId);
        uploadFile.setFileName(fileName);
        uploadFile.setFileSize(size);
        uploadFile.setMd5(md5);
        uploadFile.setBaseFileId(baseFileId);
        uploadFile.setFileSource(fileSource);
        uploadFile.setIsLog(islog);
        uploadFile.setCoshareId(coshareId);
        Observable<String> ob = SytRetrofit.getInstance()
                .createCorpUploadFile(headerMap, uploadFile);

    }


    /**
     * 获得上传文件的大小与状态，用以进行断点续传。
     * <p>
     * https://api-b.cloud.189.cn/api/api/getCorpUploadFileStatus.action
     * GET
     */
    public static void getCorpUploadFileStatus(String accessToken, String signature, String date,
                                               Long uploadFileId, Long corpId, String isLog) {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("AccessToken ", accessToken);
        headerMap.put("Signature", signature);
        headerMap.put("Date", date);
        Observable<String> ob = SytRetrofit.getInstance()
                .getCorpUploadFileStatus(headerMap, uploadFileId, corpId, isLog);

    }


    /**
     * 1M以上文件上传文件数据。
     * 使用创建上传文件接口和获取上传文件状态接口响应中的确认文件上传完成URL。
     * /corp/uploadCorpFile.action
     * <p>
     * PUT
     */
    public static void uploadCorpFile(String accessToken, String signature, String date,
                                      String corpId, String uploadFileId, String uploadFileRange,
                                      String size, String fileSource, String coshareId,
                                      String islog) {

        Map<String, String> map = new HashMap<>();
        map.put("AccessToken", accessToken);
        map.put("Signature", signature);
        map.put("FileSize", size);
        map.put("UploadFileId", uploadFileId);
        map.put("UploadFileRange", uploadFileRange);
        map.put("CorpId", corpId);
        map.put("Date", date);
        map.put("FileSource", fileSource);
        map.put("CoshareId", coshareId);
        map.put("IsLog", islog);
        Observable<String> ob = SytRetrofit.getInstance()
                .uploadCorpFile(map);
    }

    /**
     * 1M以上文件上传完成确认。
     * 使用创建上传文件接口和获取上传文件状态接口响应中的确认文件上传完成URL。
     * /corp/commitCorpFile.action
     * <p>
     * POST
     */
    public static void commitCorpFile(String accessToken, String signature, String date,
                                      Long coshareId, Long fileSource, Long operType,
                                      Long uploadFileId, Long corpId, Long isLog) {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("AccessToken ", accessToken);
        headerMap.put("Signature", signature);
        headerMap.put("Date", date);
        CommitCorpFile corpFile = new CommitCorpFile();
        corpFile.setCorpId(corpId);
        corpFile.setCoshareId(coshareId);
        corpFile.setFileSource(fileSource);
        corpFile.setOperType(operType);
        corpFile.setUploadFileId(uploadFileId);
        corpFile.setIsLog(isLog);
        Observable<String> ob = SytRetrofit.getInstance()
                .commitCorpFile(headerMap, corpFile);

    }

    /**
     * 获取文件下载地址接口。
     * https://api-b.cloud.189.cn/api/getFileDownloadUrl.action
     * <p>
     * POST
     */
    public static void getFileDownloadUrl(String accessToken, String signature,
                                          String date, Long corpId,
                                          Long coshareId, Long dt,
                                          Long fileId, Long isPreview) {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("AccessToken ", accessToken);
        headerMap.put("Signature", signature);
        headerMap.put("Date", date);
        FileDownloadUrl fileDownloadUrl = new FileDownloadUrl();
        fileDownloadUrl.setCorpId(corpId);
        fileDownloadUrl.setCoshareId(coshareId);
        fileDownloadUrl.setDt(dt);
        fileDownloadUrl.setFileId(fileId);
        fileDownloadUrl.setIsPreview(isPreview);
        Observable<String> ob = SytRetrofit.getInstance()
                .getFileDownloadUrl(headerMap, fileDownloadUrl);
    }

    /**
     * 批量下载文件接口
     * 获取文件下载地址接口。
     * https://api-b.cloud.189.cn/api/batchGetFileDownloadUrl.action
     * <p>
     * POST
     */
    public static void batchGetFileDownloadUrl(String accessToken, String signature,
                                               String date, Long corpId,
                                               Long coshareId, Long dt,
                                               String fileIdList) {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("AccessToken ", accessToken);
        headerMap.put("Signature", signature);
        headerMap.put("Date", date);
        BatchGetFileDownloadUrl batchGetFileDownloadUrl = new BatchGetFileDownloadUrl();
        batchGetFileDownloadUrl.setCorpId(corpId);
        batchGetFileDownloadUrl.setCoshareId(coshareId);
        batchGetFileDownloadUrl.setDt(dt);
        batchGetFileDownloadUrl.setFileIdList(fileIdList);
        Observable<String> ob = SytRetrofit.getInstance()
                .batchGetFileDownloadUrl(headerMap, batchGetFileDownloadUrl);
    }


    /**
     * 4.9.1文件直传接口
     * 获取一次性直传地址，有效15分钟。
     * https://api-b.cloud.189.cn/api/getDirectUploadUrls.action
     * <p>
     * GET
     */
    public static void getDirectUploadUrls(String accessToken, String signature,
                                           String date, Long corpId, Integer day,
                                           Integer urlTimes, String clientIp) {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("AccessToken ", accessToken);
        headerMap.put("Signature", signature);
        headerMap.put("Date", date);
        Observable<String> ob = SytRetrofit.getInstance()
                .getDirectUploadUrls(headerMap, corpId, day, urlTimes, clientIp);

    }

    /**
     * 4.9.2上传文件数据至资源池
     * Put 操作用来向指定 bucket 中添加一个对象，要求发送请求者对该 bucket
     * 有写权限，用户必须添加完整的对象。
     * http://cloud189corp-bj.oos-bj2.ctyunapi.cn（获取到的直连分流的资源池访问地址）
     * <p>
     * PUT
     */

    public static void realUploadFile(Long size, String type, String Date, String Authorization) {
        Map<String, Object> headerMap = new HashMap<>();
        headerMap.put("Content-Length", size);
        headerMap.put("Content-Type", type);
        Observable<String> ob = SytRetrofit.getInstance()
                .realUploadFile(headerMap, Date, Authorization);
    }


    /**
     * 4.9.34.9.3提交创建直传文件
     * 上传完文件数据后调用，提交创建文件，便于在企业云盘中查看文件。
     * <p>
     * https://api-b.cloud.189.cn/api/createFile4Direct.action
     * <p>
     * GET
     */
    public static void createFile4Direct(String accessToken, String signature,
                                         String date, Long corpId, Long parentId,
                                         String fileName, Long size, String md5,
                                         String objectId, String ETag, Long ContentLength) {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("AccessToken ", accessToken);
        headerMap.put("Signature", signature);
        headerMap.put("Date", date);
        Observable<String> ob = SytRetrofit.getInstance()
                .createFile4Direct(headerMap, corpId, parentId, fileName,
                        size, md5, objectId, ETag, ContentLength);
    }

    /**
     * 4.10对接企业微信接口
     * 4.10.1企业微信侧通讯录事件接收接口地址验证
     * 企业微信侧通讯录事件接收接口地址验证接口；特别说明接口规则不再遵循本文档通用规则
     * <p>
     * https://callback-b.cloud.189.cn/wx/receiveWXEvents
     * <p>
     * GET
     */
    public static void receiveWXEvents(String msg_signature, String timestamp, String nonce, String echostr) {


    }

    /**
     * 4.10.2企业微信通讯录事件接收
     * 企业微信通讯录事件接收接口，异步处理，接口及时返回接收成功；
     * 特别说明接口规则不再遵循本文档通用规则
     *
     *https://callback-b.cloud.189.cn/wx/receiveWXEvents
     *
     * POST
     * */


    /**
     * 4.11 对接在线文档单点接口
     *合作方单点登录至企业云在线文档
     *
     *https://b.cloud.189.cn/openAccount/onlineEdit/ssoLogin.action
     *
     * GET
     * */


}